package br.com.futibamanager.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import br.com.futibamanager.util.Constants;

import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;

/**
 * Application Lifecycle Listener implementation class StartupListener
 *
 */
public class StartupListener implements ServletContextListener {
	
	private ObjectContainer objectContainer;
	
	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent event) {
    	
    	objectContainer = 
    		Db4oEmbedded.openFile(
    			Db4oEmbedded.newConfiguration(), Constants.DB4O_FILENAME);
    	
    	event.getServletContext().setAttribute(
    		Constants.DB4O_ATTRIBUTE, objectContainer);
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent event) {
    	
    	objectContainer.close();
    }
	
}
